<template>
  <div class="medical-position">
    <div class="medical-search">
      <el-input v-model="searchValue" placeholder="病历查询"></el-input>
      <el-button style="margin-left: 20px" type="primary" icon="el-icon-edit" @click="addRecord">新增病历</el-button>
    </div>
    <div class="user-index-card-box">
      <medicalCard v-for="item in searchRecord" :key="item.id" :medicalInfo="item"></medicalCard>
    </div>
  </div>
</template>

<script>
import medicalCard from "@/components/common/medicalCard";

export default {
  components: {medicalCard},
  data(){
    return{
      searchValue: ''
    }
  },
  computed: {
    recordInfo() {
      const data = this.$store.state.adminModules.recordsList
      return data.map(item => {
        return {
          id: item.id,
          paramA: item.name,
          paramB: item.age,
          outline: item.mainSuit,
          time: item.recordTime,
        }
      })
    },
    searchRecord(){
      const _this = this
      if (!_this.searchValue) return _this.recordInfo
      return _this.recordInfo.filter(item =>
        JSON.stringify(item).indexOf(_this.searchValue) !== -1
      )
    }
  },
  async mounted() {
    await this.$store.dispatch("getRecordInfo")
  },
  methods: {
    addRecord() {
      const str = this.$route.path.split('/')[1]
      this.$store.dispatch("addRecordInfo")
      //指定跳转地址
      this.$router.push({name: `/${str}recordInfo`, params: {edit: true}})
    }
  }
}
</script>
